<template>
  <div>
    <!-- 轮播图组件 -->
    <Swiper :imgList="imgList"></Swiper>

    <!-- 功能模块网格布局 -->
    <ul class="mui-table-view mui-grid-view mui-grid-9">
      <li class="mui-table-view-cell mui-media mui-col-xs-4 mui-col-sm-3">
        <router-link :to="{ name: 'news_list' }" class="title">
          <img src="../assets/images/menu1.png" alt="新闻资讯">
          <div class="mui-media-body">新闻资讯</div>
        </router-link>
      </li>
      <li class="mui-table-view-cell mui-media mui-col-xs-4 mui-col-sm-3">
        <!-- 添加 router-link 跳转到 photo_list -->
        <router-link :to="{ name: 'photo_list' }" class="title">
          <img src="../assets/images/menu2.png" alt="图片分享">
          <div class="mui-media-body">图片分享</div>
        </router-link>
      </li>
      <li class="mui-table-view-cell mui-media mui-col-xs-4 mui-col-sm-3">
        <router-link :to="{ name: 'category' }" class="title">
          <img src="../assets/images/menu3.png" alt="商品购买">
          <div class="mui-media-body">商品购买</div>
        </router-link>
      </li>
      <li class="mui-table-view-cell mui-media mui-col-xs-4 mui-col-sm-3">
        <img src="../assets/images/menu4.png" alt="留言反馈">
        <div class="mui-media-body">留言反馈</div>
      </li>
      <li class="mui-table-view-cell mui-media mui-col-xs-4 mui-col-sm-3">
        <img src="../assets/images/menu5.png" alt="视频专区">
        <div class="mui-media-body">视频专区</div>
      </li>
      <li class="mui-table-view-cell mui-media mui-col-xs-4 mui-col-sm-3">
        <img src="../assets/images/menu6.png" alt="联系我们">
        <div class="mui-media-body">联系我们</div>
      </li>
    </ul>
  </div>
</template>

<script>
import Swiper from '../components/swiper.vue';

export default {
  data() {
    return {
      imgList: [],
    };
  },
  components: {
    Swiper,
  },
  created() {
    this.getImgList();
  },
  methods: {
    getImgList() {
      this.$indicator.open({
        text: '加载中',
      });

      this.$http.get('imglist')
        .then((res) => {
          this.$indicator.close();
          if (res.data.code === 0) {
            this.$toast('加载轮播图失败');
          } else {
            this.imgList = res.data.data;
          }
        })
        .catch((error) => {
          this.$indicator.close();
          this.$toast('请求失败，请稍后重试');
          console.error('请求失败:', error);
        });
    },
  },
};
</script>

<style lang="scss" scoped>
.mui-grid-view.mui-grid-9 {
  background-color: #fff;
  border: none;

  img {
    width: 60px;
    height: 60px;
  }
}

.mui-table-view-cell > a.title {
  display: inline;
}

.mui-grid-view.mui-grid-9 .mui-table-view-cell {
  border: 0;
}

.mui-media-body {
  font-size: 14px;
}
</style>